﻿using HotelManager.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HotelManager.Service
{
    public class TypeService: ITypeService
    {
        private readonly HttpRestClient client;
        public TypeService(HttpRestClient client)
        {
            this.client = client;
        }

        public async Task<ResultData<string>> AddAsync(RoomTypeData roomTypeBody)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/RoomType/Add";
            request.Parameter = roomTypeBody;
            return await client.ExecutePostAsync<ResultData<string>>(request);
        }

        public async Task<ResultData<string>> DeleteAsync(int roomTypeId)
        {
            BaseRequest request = new BaseRequest();
            RoomTypeIdData roomTypeIdBody = new RoomTypeIdData() { roomTypeId = roomTypeId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/RoomType/Delete";
            request.Parameter = roomTypeIdBody;
            return await client.ExecutePostAsync<ResultData<string>>(request);
        }

        public async Task<List<RoomTypeData>> GetAllAsync()
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Get;
            request.Route = $"api/RoomType/List";
            return await client.ExecuteAsync<List<RoomTypeData>>(request);
        }

        public async Task<RoomTypeData> GetFirstOrDefaultAsync(int roomTypeId)
        {
            BaseRequest request = new BaseRequest();
            RoomTypeIdData roomTypeIdBody = new RoomTypeIdData() { roomTypeId = roomTypeId };
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/RoomType/GetOne";
            request.Parameter = roomTypeIdBody;
            return await client.ExecutePostAsync<RoomTypeData>(request);
        }

        public List<RoomTypeTotalData> GetRoomTypeTotalMoney()
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Get;
            request.Route = $"api/RoomType/TotalTypePrice";
            return client.ExecuteSync<List<RoomTypeTotalData>>(request);
        }

        public ResultData<string> Update(RoomTypeData roleData)
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Post;
            request.Route = $"api/RoomType/Update";
            request.Parameter = roleData;
            return client.ExecuteSync<ResultData<string>>(request);
        }
    }
}
